﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace SC2Ranks.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            SC2RanksService service = new SC2RanksService("clansdn.org");

            Console.WriteLine("GetBaseCharacterInfoByCharacterCode");
            var player = service.GetBaseCharacterInfoByCharacterCode(Region.EU, "Kralizek", 669);
            PrintPlayerInfo(player);

            Console.WriteLine("GetBaseTeamCharacterInfoByCharacterCode");
            player = service.GetBaseTeamCharacterInfoByCharacterCode(Region.EU, "Kralizek", 669);
            PrintPlayerInfo(player);

            Console.WriteLine("GetBaseTeamCharacterInfoByCharacterCode (1v1)");
            player = service.GetTeamInfoByCharacterCode(Region.EU, "Kralizek", 669, 1);
            PrintPlayerInfo(player);

            Console.WriteLine("GetBaseTeamCharacterInfoByCharacterCode (2v2)");
            player = service.GetTeamInfoByCharacterCode(Region.EU, "Kralizek", 669, 2);
            PrintPlayerInfo(player);

            Console.WriteLine("MassGetPlayers");
            var players = service.MassGetPlayers(new PlayerSearchInfo[] { 
                PlayerSearchInfo.CreateByCharacterCode(Region.EU, "Kralizek", 669),
                PlayerSearchInfo.CreateByCharacterCode(Region.EU, "Kemp", 124),
                PlayerSearchInfo.CreateByCharacterCode(Region.EU, "Raz", 211)
            });

            foreach (var p in players)
                PrintPlayerInfo(p);
            
            Console.ReadLine();
        }

        static void PrintPlayerInfo(PlayerInfo player)
        {
            Console.WriteLine("{2} - {0}.{1}", player.Name, player.CharacterCode, player.Region);
            Console.WriteLine("\tBattleNet-ID: {0}", player.BattleNetID);
            Console.WriteLine("\tAchievement points: {0}", player.AchievementPoints);
            Console.WriteLine("\tLast update at: {0}", player.UpdatedAt.ToLocalTime());

            if (player.Teams != null && player.Teams.Any())
            {
                Console.WriteLine("Teams:");
                foreach (var team in player.Teams.OrderBy(t => t.Bracket))
                {
                    Console.WriteLine("\t{0}v{0}: {1} ({2} wins, {3} losses, {4:P})", team.Bracket, team.League, team.Wins, team.Losses, team.Ratio);

                    if (team.Members != null && team.Members.Any())
                    {
                        foreach (var member in team.Members)
                        {
                            Console.WriteLine(string.Format("\t- {0}.{1} ({2})", member.Name, member.CharacterCode, member.FavoriteRace));
                        }
                    }
                }
            }

            Console.WriteLine();
        }
    }
}
